import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { MenuController } from './menu/menu.controller'
import { MenuModule } from './menu/menu.module'
import { ConfigModule, ConfigService } from '@nestjs/config'
// import envConfig from '../config/env'
import { TypeOrmModule } from '@nestjs/typeorm'
import { UserModule } from './user/user.module'
import { UserController } from './user/user.controller'
import { OssModule } from './common/oss/oss.module'
// import { JwtAuthGuard } from './auth/guards/jwt-auth.guard'
import { JwtModule } from '@nestjs/jwt'
import { AuthModule } from './auth/auth.module'
import { RobotModule } from './robot/robot.module'
import { CommentModule } from './comment/comment.module'
import { CommentController } from './comment/comment.controller'
import { OrderModule } from './order/order.module'
import { WebhookController } from './webhook/webhook.controller'
import { FavoriteModule } from './favorite/favorite.module'
import { MenuDetailModule } from './menuDetail/menuDetail.module'
import { PointsModule } from './points/points.module'
import { VerificationModule } from './verification/verification.module'
// import { OrderController } from './order/order.controller'
import { RedisModule } from './redis/redis.module';
import { RefundModule } from './refund/refund.module'
import { ScheduleModule } from '@nestjs/schedule'
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true, // 设置全局
      // envFilePath: [envConfig.path]
      envFilePath: `.env.${process.env.NODE_ENV || 'development'}`
    }),
    TypeOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => ({
        type: 'mysql',
        entities: [__dirname + '/**/*.entity{.ts,.js}'],
        host: config.get('DB_HOST'),
        port: config.get('DB_PORT'),
        username: config.get('DB_USERNAME'),
        password: config.get('DB_PASSWORD'),
        database: config.get('DB_DATABASE'),
        timezone: '+08:00',
        autoLoadEntities: true, // 自动加载实体类
        synchronize: process.env.NODE_ENV === 'production' ? false : true, // 定义数据库表结构与实体类字段同步(这里一旦数据库少了字段就会删除，所以生产环境不能用) 
      })
    }),
    ScheduleModule.forRoot(),
    MenuModule,
    UserModule,
    OssModule,
    JwtModule,
    AuthModule,
    RobotModule,
    CommentModule,
    OrderModule,
    FavoriteModule,
    MenuDetailModule,
    PointsModule,
    VerificationModule,
    RedisModule,
    RefundModule,
  ],
  controllers: [AppController, MenuController, UserController, CommentController, WebhookController],
  providers: [AppService],
})
export class AppModule { }
